#include <stdio.h>
#include <time.h>
#include <sys/time.h>


void convert_time_t_2_tm(){
    printf("%s\n", __FUNCTION__);

    time_t rawtime = time(NULL); // 获取当前时间
    printf("seconds=%llu\n", rawtime);
    struct tm *timeinfo = localtime(&rawtime); // 转换为本地时间
 
    int year = timeinfo->tm_year + 1900; // tm_year是从1900年起的年数
    int month = timeinfo->tm_mon + 1; // tm_mon是从0开始的月数
    int day = timeinfo->tm_mday; // 日
    
    printf("Date: %d-%02d-%02d\n", year, month, day);

}

void convert_timeval_2_tm(){
    printf("%s\n", __FUNCTION__);

    struct timeval tv;
    gettimeofday(&tv, NULL);
    printf("tv.tv_sec=%llu, tv.tv_usec=%llu\n", tv.tv_sec, tv.tv_usec);

}


int main(int argc, char *argv[]){
    convert_time_t_2_tm();
    convert_timeval_2_tm();
    return 0;
}